<?php

namespace iBrand\Shop\Core;


use iBrand\Component\User\Repository\UserRepository;
use iBrand\Shop\Core\Repositories\ClerkRepository;
use iBrand\Shop\Core\Repositories\Eloquent\ClerkRepositoryEloquent;
use iBrand\Shop\Core\Repositories\Eloquent\UserRepositoryEloquent;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use Event;

class ServiceProvider extends BaseServiceProvider
{

    protected $subscribe = [
        'iBrand\Shop\Core\Listeners\RefundEventListener',
        'iBrand\Shop\Core\Listeners\UserEventListener',
        /*'iBrand\Shop\Core\Listeners\UserLoginEventListener',*/
    ];

    public function boot()
    {
        $this->registerMigrations();

        if ($this->app->runningInConsole()) {

            $this->publishes([
                __DIR__ . '/config.php' => config_path('o2o.php'),
            ]);
        }

        foreach ($this->subscribe as $subscriber) {
            Event::subscribe($subscriber);
        }

        Schema::defaultStringLength(191);
    }

    protected function registerMigrations()
    {
        return $this->loadMigrationsFrom(__DIR__ . '/../migrations');
    }

    public function register()
    {
        $this->app->bind(ClerkRepository::class, ClerkRepositoryEloquent::class);

        $this->app->bind(UserRepository::class, UserRepositoryEloquent::class);

        $this->app->make('iBrand\ScheduleList')->add(Schedule::class);
    }

}
